test(query-core): assert exact cache event payloads in subscribe callbacks#11053
Merged
Merged
Conversation
|
View your CI Pipeline Execution ↗ for commit 971cf30
☁️ Nx Cloud last updated this comment at |
Contributor
📝 WalkthroughWalkthroughThe PR strengthens query-core cache subscription tests by asserting complete event payloads, including event type and the associated mutation, query, or observer. ChangesCache notification tests
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Contributor
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/query-core/src/__tests__/queryClient.test.tsx`:
- Around line 1617-1620: Update the callback assertion in the queryCache event
test to verify the emitted reset action alongside type and query. Extend the
expect.objectContaining payload for the updated event with the expected reset
action, preserving the existing query assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b62d349c-7490-446d-80ef-365de705030f
📒 Files selected for processing (5)
packages/query-core/src/__tests__/mutationCache.test.tsxpackages/query-core/src/__tests__/query.test.tsxpackages/query-core/src/__tests__/queryCache.test.tsxpackages/query-core/src/__tests__/queryClient.test.tsxpackages/query-core/src/__tests__/queryObserver.test.tsx
Contributor
size-limit report 📦
|
e689aa7 to
cd7feeb
Compare
cd7feeb to
d31ecb5
Compare
d31ecb5 to
971cf30
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
QueryCache/MutationCachesubscribe callbacks receive an event object whosequery/mutationis an instance the library creates internally. Several tests only checked that the callback fired (toHaveBeenCalled()) or matched thetypefield partially (objectContaining), leaving the instance and the exact payload shape unverified.Each test can recover the instance from the cache (
find({ queryKey }), or the in-scopemutation/observer), so the assertions now pin the full event object. Where the callback fires multiple times in a known order, the assertion is also pinned to the right call (addedis the first event,removedfrom gc is the last).queryCache—addedevents (4 tests) — asserttoHaveBeenNthCalledWith(1, { query, type: 'added' });addedis always the first event, and the earliertoHaveBeenCalledWith/toHaveBeenCalled()did not pin the call positionmutationCache— "should still notify removal..." — droppedobjectContainingso{ type: 'removed', mutation }also asserts no extra fields (single call is already guaranteed bytoHaveBeenCalledTimes(1))query— "queries should be garbage collected even if they never fetched" — captures the query before gc removes it, then assertstoHaveBeenLastCalledWith({ type: 'removed', query })(gc removal is the last event)queryObserver— "should notify cache listeners when setOptions is called" — asserts the full{ type: 'observerOptionsUpdated', query, observer }(single call is already guaranteed bytoHaveBeenCalledTimes(1))queryClient— "should notify listeners when a query is reset" —toHaveBeenCalled()→toHaveBeenNthCalledWith(1, objectContaining({ type: 'updated', query, action: { type: 'setState' } }))(theaction.statesnapshot is left open, as it depends on timing)✅ Checklist
🚀 Release Impact
Summary by CodeRabbit